//内容的规则
import 'dart:convert';

import 'package:flutter_book/data/model/yck/rule/rule.dart';

class ContentRule {
  Rule? content;
  Rule? nextContentUrl;
  Rule? webJs;
  Rule? sourceRegex;
  Rule? replaceRegex; //替换规则
  Rule? imageStyle;


  ContentRule(this.content, this.nextContentUrl, this.webJs, this.sourceRegex, this.replaceRegex, this.imageStyle);

  ContentRule.fromJson(dynamic json) {
    json = checkJson(json);
    content = json['content'];
    nextContentUrl = json['nextContentUrl'];
    webJs = json['webJs'];
    sourceRegex = json['sourceRegex'];
    replaceRegex = json['replaceRegex'];
    imageStyle = json['imageStyle'];
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map['content'] = content;
    map['nextContentUrl'] = nextContentUrl;
    map['webJs'] = webJs;
    map['sourceRegex'] = sourceRegex;
    map['replaceRegex'] = replaceRegex;
    map['imageStyle'] = imageStyle;
    return map;
  }

  Map<String,dynamic> checkJson(dynamic jsonString){
    if (jsonString == null) {
      jsonString =Map();
    }else if(jsonString is String){
      try{
        jsonString = json.decode(jsonString);
        if(!(jsonString is Map<String,dynamic>)){
          jsonString =Map();
        }
      }catch (e){
        jsonString =Map();
      }
    }else if(jsonString is ContentRule){
      jsonString = jsonString.toJson();
    }else if(!(jsonString is Map<String,dynamic>)){
      jsonString =Map();
    }
    return jsonString;
  }

}
